"use strict";
/*
 * @Author: wangjing wangjin122@qq.com
 * @Date: 2024-02-23 15:09:24
 * @LastEditors: wangjing wangjin122@qq.com
 * @LastEditTime: 2024-02-23 16:30:47
 * @FilePath: \泛型\index.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
// 1. 动态类型
function xiaoman(a, b) {
    return [a, b];
}
xiaoman('1', '2');
let a = 1;
let data = {
    msg: 'xxxx'
};
// 1.3 泛型的高级用法 可以设置默认值
function add(a, b) {
    return [a, b];
}
add(1, false);
// 2 泛型应用示例
const axios = {
    get(url) {
        return new Promise((resolve, reject) => {
            let xhr = new XMLHttpRequest();
            xhr.open('GET', url);
            xhr.onreadystatechange = () => {
                if (xhr.readyState == 4 && xhr.status == 200) {
                    resolve(JSON.parse(xhr.responseText));
                }
            };
            xhr.send(null);
        });
    }
};
axios.get('./data.json').then(res => {
    console.log(res);
});
